<template>
	<div class="llf_content">
		<SearchHeader @search="onSearch" :selectform="selectform" placeholder="项目名称搜索" />
		<ItemList :tableData="dataSource" @operation="TableOperation" ref="reportRef" />
		<MyPagination :total="total" @change="onPaginationChange" ref="pageRef" />
	</div>
</template>

<script lang="ts" setup>
	import { onMounted, ref } from "vue";
	import { Modal } from 'ant-design-vue';
	import { findList } from "@/api/item";
	import options from "@/common";
	import message from "@/utils/message";
	import ItemList from "./component/ItemList.vue";
	
	const selectform = ref<any>([
		// { title: '状态', childer:[], width: '50px', contWidth: '150px',class: 'status', },
		{ title: '状态', childer: options.SYSTEMSTATUS_OPTION, width: '50px',class: 'status' },
	]);
	const dataSource = ref([]);
	const reportRef = ref();
	const total = ref(0);
	const searchData = ref({ page:1,size:20 });
	const currentIteminfo = ref({});
	const pageRef = ref();
	
	async function getFn(){
		const res = await findList(searchData.value);
		if(!res) return;
		dataSource.value = res.list;
		total.value = res.total;
	}
	
	const onSearch = (inputValue: string, obj: any) => {	//搜索---子组件
		let SEARCH_VALUE = {};
		SEARCH_VALUE = obj;
		SEARCH_VALUE["keyword"] = inputValue;
		// console.log(SEARCH_VALUE, "SEARCH_VALUE")
		searchData.value.page = 1;
		pageRef.value.changeCurrent();
		searchData.value = { ...searchData.value, ...SEARCH_VALUE };
		getFn();
	};
	
	const onPaginationChange = (value: { page: number; pageSize: number }) => { // 页码与页面数量
		const { pageSize, page } = value;
		searchData.value = { ...searchData.value, page, limit: pageSize };
		getFn();
	};
	
	const TableOperation = async (index: string, row: any = {}) => { // 表格操作
		currentIteminfo.value= row;
		switch(index){
			case 'look':{
				
			};break;
			case 'delete':{
				Modal.confirm({
				    content: `您确定要永久删除吗？`,
				    async onOk() {
				       const res = await deletedFn({ deletedFn:[row.id] });
					   if(!res) return;
					   message.success("删除成功");
					   getFn();
				    },
				    // eslint-disable-next-line @typescript-eslint/no-empty-function
				    onCancel() {},
				});
			};break;
			default:console.log(1);
		}
	}
	
	onMounted(()=>{
		getFn();
	});
</script>

<style>
</style>